package cn.edu.hqu.cst.lingshou03.mapper;

import cn.edu.hqu.cst.lingshou03.model.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("INSERT INTO orders (customer_name, product, quantity, status) VALUES (#{customerName}, #{product}, #{quantity}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertOrder(Order order);

    @Update("UPDATE orders SET status = #{status} WHERE id = #{id}")
    void updateOrderStatus(@Param("id") Long id, @Param("status") String status);

    @Select("SELECT * FROM orders WHERE id = #{orderId}")
    Order selectById(@Param("orderId") Long orderId);

    // 对于 insert 和 updateById 方法，您可以在这里添加注解，或者使用 XML 映射文件
    // 如果您选择使用注解，以下是示例
    @Insert("INSERT INTO orders (customer_name, product, quantity, status) VALUES (#{customerName}, #{product}, #{quantity}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Order order);

    @Update("UPDATE orders SET customer_name = #{customerName}, product = #{product}, quantity = #{quantity}, status = #{status} WHERE id = #{id}")
    void updateById(Order order);
    @Select("SELECT * FROM orders")
    List<Order> selectAll();
}
